#pragma once


template<typename T>
class singleton 
{
public:
	static T* get_instance() 
	{
		if (instance == NULL)
		{
			new_instace();
		}
		return instance;
	}
	static void new_instace() 
	{
		delete_instance();
		instance = new T();
	}

	static void delete_instance() 
	{
		if(instance)
		{
			T* pTmp = instance;
			instance = NULL;
			delete pTmp;
		}
	}

	static void SetInstanceNull()
	{
		instance = NULL; 
	}

protected:
	singleton() 
	{ 
	}
	virtual ~singleton() 
	{ 
		if(instance)
		{
			delete instance;
			instance = NULL;
		}
	}
	static T* instance;
private:
	singleton(const singleton&);
	singleton& operator=(const singleton&);

};
template<typename T> T* singleton<T>::instance = NULL;